package com.quanxiaoha.weblog.admin.service.Impl;

import com.quanxiaoha.weblog.admin.model.vo.file.UploadFileRspVO;
import com.quanxiaoha.weblog.admin.model.vo.user.GetUserInfoRspVO;
import com.quanxiaoha.weblog.admin.model.vo.user.UpdateAdminUserPasswordReqVO;
import com.quanxiaoha.weblog.admin.service.AdminFileService;
import com.quanxiaoha.weblog.admin.service.AdminUserService;
import com.quanxiaoha.weblog.common.domain.mapper.UserMapper;
import com.quanxiaoha.weblog.common.enums.ResponseCodeEnum;
import com.quanxiaoha.weblog.common.utils.AliOSSUtils;
import com.quanxiaoha.weblog.common.utils.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Service
@Slf4j
public class AdminFileServiceImpl implements AdminFileService {

    @Autowired
    private AliOSSUtils aliOSSUtils;

    @Override
    public Response upload(MultipartFile file) {
        try {
            //上传到阿里云oss
            String url = aliOSSUtils.upload(file);
            //返回oss的URL
            return Response.success(new UploadFileRspVO(url));
        } catch (IOException e) {
            log.error("==> 上传文件至 OSS 错误: ", e);
            return Response.fail(ResponseCodeEnum.FILE_UPLOAD_FAILED);
        }
    }
}
